"""
应用程序入口
"""
import sys
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import Qt

try:
    from .main_window import MIMainWindow
    from .cpp_bridge import cpp_engine
    from .config import CONFIG
except ImportError:
    from main_window import MIMainWindow
    from cpp_bridge import cpp_engine
    from config import CONFIG


def main() -> int:
    """主函数"""
    # 启用高DPI支持
    QApplication.setHighDpiScaleFactorRoundingPolicy(
        Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
    )
    
    app = QApplication(sys.argv)
    app.setApplicationName("MI Testing Tool")
    app.setOrganizationName("MI Team")
    
    # 初始化C++引擎（如果启用）
    if CONFIG.use_cpp_engine:
        print("Initializing C++ engine...")
        cpp_engine.initialize()
    
    # 创建主窗口
    window = MIMainWindow()
    window.show()
    
    # 显示启动信息
    print("=" * 60)
    print("MI - 新一代测试工具 v1.0")
    print("=" * 60)
    print(f"采样频率: {CONFIG.sampling.sample_rate} Hz")
    print(f"缓冲区大小: {CONFIG.sampling.buffer_size:,} events")
    print(f"批次大小: {CONFIG.sampling.batch_size:,} events")
    print(f"C++引擎: {'启用' if CONFIG.use_cpp_engine else '禁用'}")
    print(f"虚拟滚动: {'启用' if CONFIG.visualization.enable_virtual_scroll else '禁用'}")
    print("=" * 60)
    
    return app.exec()


if __name__ == '__main__':
    sys.exit(main())
